//// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest.action
//
//import com.intellij.icons.AllIcons
//import com.intellij.openapi.actionSystem.ActionUpdateThread
//import com.intellij.openapi.actionSystem.AnActionEvent
//import com.intellij.openapi.actionSystem.PlatformDataKeys
//import com.intellij.openapi.components.service
//import com.intellij.openapi.components.serviceIfCreated
//import com.intellij.openapi.fileEditor.FileEditorManager
//import com.intellij.openapi.project.DumbAwareAction
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.pullrequest.GCPRVirtualFile
//import com.linqingying.gitcode.pullrequest.ui.toolwindow.model.GCPRToolWindowViewModel
//import java.util.function.Supplier
//
//class GCPRSelectPullRequestForFileAction : DumbAwareAction(GitCodeBundle.messagePointer("pull.request.select.action"),
//                                                           Supplier { null },
//                                                           AllIcons.General.Locate) {
//
//  override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
//
//  override fun update(e: AnActionEvent) {
//    val project = e.project
//    if (project == null) {
//      e.presentation.isEnabledAndVisible = false
//      return
//    }
//
//    val projectVm = project.serviceIfCreated<GCPRToolWindowViewModel>()?.projectVm?.value
//    if (projectVm == null) {
//      e.presentation.isEnabledAndVisible = false
//      return
//    }
//
//    e.presentation.isVisible = true
//    val file: GCPRVirtualFile? = FileEditorManager.getInstance(project).selectedFiles.filterIsInstance<GCPRVirtualFile>().firstOrNull()
//    e.presentation.isEnabled = file != null && file.repository == projectVm.repository
//  }
//
//  override fun actionPerformed(e: AnActionEvent) {
//    val project = e.getData(PlatformDataKeys.PROJECT) ?: return
//    val file = FileEditorManager.getInstance(project).selectedFiles.filterIsInstance<GCPRVirtualFile>().first()
//    project.service<GCPRToolWindowViewModel>().activateAndAwaitProject {
//      if (file.repository == repository) {
//        viewPullRequest(file.pullRequest)
//      }
//    }
//  }
//}
